import { defineStore } from 'pinia';
import type { User } from '@auth0/auth0-vue';
import { useAuth0 } from '@auth0/auth0-vue';

export const useAuthStore = defineStore('authStore', {
  state: () => ({
    // 定义认证相关的状态
    // isLoggedIn: false,
    user: null as any,
    isAuthenticated: false
  }),
  actions: {
    // 设置认证状态
    setAuthState(isAuthenticated: boolean, user: User | null) {
      this.isLoggedIn = isAuthenticated;
      this.user = user;
    },
    async checkAuth() {
      const auth0 = useAuth0()
      this.isAuthenticated = await auth0.isAuthenticated
      this.user = await auth0.user
    }
    // 定义认证相关的操作
    // login() {
    //   this.isLoggedIn = true;
    // },
    // logout() {
    //   this.isLoggedIn = false;
    // },
  },
  // 启用持久化插件，并指定要持久化的属性
  // persist: {
  //   enabled: true,
  //   strategies: [
  //     {
  //       key: 'authStore',
  //       storage: localStorage,
  //       paths: ['isLoggedIn']
  //     }
  //   ]
  // }
});